package query

import (
	"errors"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"

	"github.com/photoprism/photoprism/internal/ai/face"
	"github.com/photoprism/photoprism/internal/entity"
	"github.com/photoprism/photoprism/pkg/rnd"
)

func TestFaces(t *testing.T) {
	t.Run("Known", func(t *testing.T) {
		results, err := Faces(true, false, false, false)

		if err != nil {
			t.Fatal(err)
		}

		assert.GreaterOrEqual(t, len(results), 1)

		for _, val := range results {
			assert.IsType(t, entity.Face{}, val)
		}
	})
	t.Run("Hidden", func(t *testing.T) {
		results, err := Faces(false, false, true, false)

		if err != nil {
			t.Fatal(err)
		}

		assert.GreaterOrEqual(t, len(results), 1)
	})
	t.Run("Ignored", func(t *testing.T) {
		results, err := Faces(false, false, true, true)

		if err != nil {
			t.Fatal(err)
		}

		assert.GreaterOrEqual(t, len(results), 1)
	})
	t.Run("Unmatched", func(t *testing.T) {
		results, err := Faces(false, true, false, false)

		if err != nil {
			t.Fatal(err)
		}

		assert.GreaterOrEqual(t, len(results), 1)

		for _, val := range results {
			assert.IsType(t, entity.Face{}, val)
		}
	})
}

func TestManuallyAddedFaces(t *testing.T) {
	t.Run("Ok", func(t *testing.T) {
		results, err := ManuallyAddedFaces(false, false, "")

		if err != nil {
			t.Fatal(err)
		}

		assert.GreaterOrEqual(t, len(results), 1)

		for _, val := range results {
			assert.IsType(t, entity.Face{}, val)
		}
	})
	t.Run("Hidden", func(t *testing.T) {
		results, err := ManuallyAddedFaces(true, false, "")

		if err != nil {
			t.Fatal(err)
		}

		assert.Empty(t, results)
	})
	t.Run("SpecificSubject", func(t *testing.T) {
		results, err := ManuallyAddedFaces(false, false, "foobar")

		if err != nil {
			t.Fatal(err)
		}

		assert.Empty(t, results)
	})
}

func TestMatchFaceMarkers(t *testing.T) {
	const faceFixtureId = "ms6sg6b1wowuy444"

	if m, err := MarkerByUID(faceFixtureId); err != nil {
		t.Fatal(err)
	} else if m == nil {
		t.Fatal("marker is nil")
	} else {
		assert.Empty(t, m.SubjUID)
	}

	// Reset subj_uid.
	if err := Db().Model(&entity.Marker{}).
		Where("subj_src = ?", entity.SrcAuto).
		Where("subj_uid = ?", "js6sg6b1qekk9jx8").
		UpdateColumn("subj_uid", "").Error; err != nil {
		t.Fatal(err)
	}

	affected, err := MatchFaceMarkers()

	if err != nil {
		t.Fatal(err)
	}

	assert.Equal(t, int64(2), affected)

	if m, err := MarkerByUID(faceFixtureId); err != nil {
		t.Fatal(err)
	} else if m == nil {
		t.Fatal("marker is nil")
	} else {
		assert.Equal(t, "js6sg6b1qekk9jx8", m.SubjUID)
	}
}

func TestRemoveAnonymousFaceClusters(t *testing.T) {
	removed, err := RemoveAnonymousFaceClusters()

	if err != nil {
		t.Fatal(err)
	}

	assert.Equal(t, 2, removed)
}

func TestCountNewFaceMarkers(t *testing.T) {
	t.Run("All", func(t *testing.T) {
		assert.GreaterOrEqual(t, CountNewFaceMarkers(0, 0), 1)
	})
	t.Run("ScoreTen", func(t *testing.T) {
		assert.GreaterOrEqual(t, CountNewFaceMarkers(0, 10), 1)
	})
	t.Run("SizeNum160", func(t *testing.T) {
		assert.GreaterOrEqual(t, CountNewFaceMarkers(160, 0), 1)
	})
	t.Run("ScoreNum50AndSizeNum160", func(t *testing.T) {
		assert.GreaterOrEqual(t, CountNewFaceMarkers(160, 50), 1)
	})
}

func TestMergeFaces(t *testing.T) {
	t.Run("SameSubjects", func(t *testing.T) {
		face1 := entity.NewFace(
			"jqynvsf28rhn6b0c",
			entity.SrcManual,
			face.Embeddings{
				face.Embedding{0.10730543085474682, -0.007740289179353713, 0.04013410115400314, 0.01458170011165962, -0.033333988977870946, 0.06636234022813034, -0.00010941258007316575, 0.0266348918046072, -0.05017391628723953, 0.026034562221256254, -0.03388911566430759, -0.03461048494812202, 0.040559725024994844, 0.02683793627304573, -0.00972269717541027, -0.07836494561032105, -0.022470260049817198, 0.011276674801708603, -0.05526434009558201, 0.014401617237932205, -0.031258523568474236, -0.05416104192368187, -0.05567222379755878, 0.017950877029356768, -0.016397424193561935, 0.062346790423413276, -0.019043469394284057, 0.04085343435437774, -0.05627231374819698, 0.002355368169155769, 0.07268979656775187, -0.0015096598716884627, -0.030188596848975374, -0.030941932784964564, -0.02826790015985233, -0.05420075791573048, -0.015742074680253033, 0.019360258910790157, -0.008227027287290193, -0.08797317745792674, -0.07358703463505077, 0.09688007249803735, 0.015168583267354964, -0.034569315837825396, 0.054231690688333986, 0.018033145214487362, 0.01579093209709463, -0.09204238994311237, 0.08645247031890774, -0.10499936100221444, 0.022421303168151857, 0.005288450124515152, -0.017391072021601867, 0.011218363053184624, -0.08478270589438915, 0.0038618527485391615, -0.023381522484070015, -0.05428399272960853, -0.049397680150033, 0.04006855272634697, -0.056704127236808774, -0.00958812557516262, -0.024006645464504622, -0.0073450501057456975, -0.03138197361666756, -0.013765138786817361, 0.01162637563227787, 0.0023935177775817563, 0.08953138773108768, 0.05337418268588829, -0.012870218945196915, 0.03652425150877475, -0.027783526080406188, -0.019489638927241745, -0.01591402705199299, -0.005031992847164803, -0.014592982936285286, -0.03540697236418762, 0.015595597412254449, 0.004689344744109726, -0.009276015175478172, 0.0058068592886232374, 0.10480716412028504, 0.0169216338187767, -0.0159497901004467, 0.04574707649004688, -0.012214007484710122, -0.04849749380776977, 0.054958586523843764, 0.055898306713647844, -0.05052226642217827, 0.008803732924324036, 0.02326267119630642, 0.047305830959801676, 0.04497242295638694, 0.020850376996620942, 0.01314765746152954, -0.06768179592533874, 0.05844347174572754, -0.03379152370001783, 0.009412363744416903, 0.04876727547273407, 0.03299943491180715, 0.01981742466488743, 0.0547951049219265, 0.020208802772381018, -0.08163521584288311, -0.038910958658009524, -0.004049565234655952, -0.02227413252290535, -0.0176418922441086, 0.0568860088455925, -0.03240221023084612, 0.0018760896289435579, -0.03234445138420723, 0.007601825631139565, 0.004916589611196899, -0.07292478312312889, 0.021712048014592936, 0.008807552270011749, 0.0045489283733609, 0.018861112444398878, -0.0341377092368577, -0.06305481604926585, 0.039113288345403674, -0.01390809621003151, -0.04930861238819008, 0.02377057523982868, 0.019087416355893325, -0.013899296822125817, 0.02251690464443226, 0.08074113913260841, -0.018922226267959787, 0.07189693789385795, 0.060660045672045707, -0.023638294307546808, -0.006141792394255906, -0.06662582397409247, -0.013895529799502565, 0.016608829923953898, -0.00390724028582611, 0.05038048671591301, -0.015355035841564064, -0.0008532485082750321, -0.004694504582768126, -0.016610601585741958, 0.008180847821889228, -0.04035771976174698, 0.01847608156922703, 0.08409907464663602, -0.029978496458568385, -0.06499117178372192, 0.07448235046571827, 0.10142187900247382, -0.023405319141915855, 0.05237413796294822, 0.04315940939233541, -0.02349721355909328, 0.012594679585403442, -0.10457832859776592, 0.001468614040066719, 0.0165479676672657, -0.07708675453700256, -0.05102918249748802, 0.045642631412478735, -0.004785828004440499, 0.0203317336356945, -0.02006395174473057, 0.04201285855375195, 0.032883700123707296, 0.0477916040669878, 0.08070634492548084, -0.09245629058029556, 0.05112703265588493, -0.006224603994954872, -0.0005257819460310555, 0.005513055457300567, 0.02521921247766018, 0.012207323409280013, -0.009936333046208725, -0.007426916158089448, 0.027260071572856714, 0.006004036209329835, -0.039462719505699156, 0.04428369084658737, 0.005021041270120048, 0.00955255667591259, -0.024385389176467896, 0.06930311634011002, -0.0389855151682066, 0.009325780048200605, 0.0067487294106089776, -0.0538568250434906, -0.04132319716445885, 0.005287871307727813, 0.02836177144018917, 0.016369665767238237, -0.02612976718916588, 0.0781344821977253, 0.0124423230052565, 0.007052016124275589, 0.07093038059380721, -0.040975969278632354, 0.05987170546998787, 0.0429845054696949, 0.06377765311330413, -0.054260408781722336, 0.017124075467253648, 0.011034745989844896, -0.01129856537228031, -0.03058279355517101, -0.052326615682374664, 0.06340472755555274, -0.007235566082305412, 0.08209440086026383, -0.0037407900405261995, -0.02100836190159107, 0.051361881913555715, 0.035520336595121764, 0.019260735587613487, 0.04814414379586697, -0.010566343916274241, -0.03353529212573547, 0.05283452853813282, -0.027749841873006824, -0.03820509264906912, -0.0015166780129867554, 0.02487160170807457, 0.03048850776525669, -0.030538799520168875, 0.0921192664219265, 0.03269134465648327, -0.031787506815418434, -0.01908650508301182, 0.05982613160244779, -0.053232109332236294, -0.03650761934345913, 0.0026813365359365463, 0.032588356136758805, -0.032364926929593085, 0.07780626359498405, 0.044541174425177764, 0.011626562325897788, 0.03554684517681643, -0.030510870967539787, -0.04088990689640999, 0.07105028789278889, 0.03138784011465073, -0.06342823476303319, 0.09164142434876824, -0.0112280279000453, -0.04595559070266152, 0.08798781996626949, 0.026803936697537615, -0.0014241986940294257, -0.020834715982498548, 0.023556784775891685, 0.008996215819517326, -0.0012677171940084454, -0.07692881668502807, 0.024615258007191814, 0.02948731386628723, 0.06911119150276565, -0.041541930091072085, 0.07317672894504547, -0.012252912262506771, -0.03429316172188286, 0.03286905748134327, 0.025736928383919527, 0.003926683415351601, 0.006255630871762562, -0.020806247741813468, 0.0675457214042778, 0.007579460672946357, 0.012004441173839569, -0.028187582314963343, -0.0018772867526912688, -0.01844064376148571, -0.05389302147970715, -0.04154738243111, -0.05912346626385308, -0.003186127453911171, -0.015869915592464562, 0.036601020266580665, -0.08332522355102062, -0.015594113206121387, 0.010554298175920372, 0.009863903175943527, -0.04408378851017952, -0.01321298950931368, -0.026788807387387467, -0.00905998101737915, -0.07901183432849217, 0.022626760559060342, 0.05966787504726859, -0.0373913765745697, -0.00620443077226124, -0.005321248754354935, -0.05629461318153381, -0.04339327553344822, 0.03066110013017902, -0.0560899433873785, 0.029585001932263853, -0.06142458606396866, 0.018855098215825178, 0.03336997769082436, -0.07772387048591708, 0.02869667860757885, 0.04751144987925148, 0.07131169258731747, 0.01554444873138424, -0.019102520424152183, -0.06713599618322277, 0.021553602847260475, 0.022784952935549926, -0.07224605423420524, -0.03428428022313595, 0.025510370273970604, -0.042455744666400605, 0.024999596293880464, 0.0007267671517935561, -0.007103063657435513, 0.051193967364198685, -0.03918299151588478, -0.05340270113635778, -0.0005553757678619388, -0.04361415384515381, -0.05659870360464592, -0.003001301568729019, -0.10493783691904449, 0.007865782491956196, -0.010459198798326888, 0.03839990013440418, -0.029396389004837837, 0.04123072916591454, -0.003870788638888664, 0.011576299454542732, 0.021793958225202522, 0.0013144587776207917, -0.024084851461598205, -0.007895128372669067, 0.02794634672595444, 0.013256276108802492, -0.06581846043538475, -0.03512838380870453, 0.010219935781849479, 0.041956290830379675, -0.02193645334812136, 0.036522118692461206, -0.04014683200312634, -0.007509486720670319, 0.025035869046040268, 0.03341998480559387, -0.03562761249035026, 0.04892323307058029, -0.030771232001644132, -0.016917612628533363, 0.002604945885121918, -0.044643074882380486, 0.01154372547133419, -0.021955625942386627, 0.018907365975515553, 0.03550167291446045, 0.01069377167082758, 0.00010183658435096768, -0.04899959038740444, 0.04724968668608978, -0.01864932432341235, 0.0591259089168789, 0.07907125494612216, 0.028897156624642945, 0.01633692932619137, 0.06420496597867965, 0.018129071607111358, -0.06522170992608013, -0.03939954941189146, 0.04130569647272587, 0.04419998725251961, 0.04542913027885341, 0.018470383181769943, 0.008568164058957863, -0.06659949697784996, -0.053012251715078354, -0.020253768667636778, -0.0428765378002491, 0.07184141544699574, 0.02058260375849676, -0.03779574153167915, 0.0021254573788347247, 0.00922705617390442, -0.06903300705643031, 0.048223514541707424, -0.008124176700399017, 0.06623217639861775, 0.011399885879904556, 0.13320644195552445, -0.015707634324862062, 0.004298537653726769, 0.007440328888434029, -0.03552852988830433, 0.006549433453245544, -0.019685784628289793, 0.001693401851796341, 0.050209905835451124, 0.023254144681681632, -0.04905436637160683, -0.01058279299507389, 0.06261640349854469, -0.07554102380998802, -0.010803172210683784, 0.04001997347501145, -0.013296409033855438, 0.056829244201244355, 0.029110596151947783, 0.006392164909307861, -0.0035876165295053485, -0.019022594469099045, -0.06487911801050472, 0.02178870949222603, 0.05293369045270252, 0.0014374271403566358, 0.02058438161717472, -0.05258523574003887, -0.03312468141761551, 0.051533518133239746, 0.03929023312081566, -0.07294044148252202, 0.01607557897360134, -0.0007034383966050719, 0.014925192443655966, 0.051449392859268764, -0.06079890988933106, -0.04363216685223599, 0.028568039422766974, 0.045766175851156804, 0.07275596444172669, -0.02276483221781349, 0.09294405910429002, 0.06625853254336929, -0.04167032707059745, -0.04751508792911625, -0.014774199240300752, 0.023224616626467326, -0.01281115503053608, 0.03472993899021339, 0.008343472536062031, -0.011408440443860645, 0.004419146704378701, 0.05045044130775452, -0.03518939370823498, -0.04170123182437134, 0.022208642446600917, 0.07141607704347333, -0.04112406919064011, 0.03227901691925602, 0.03527487398910847, -0.029543274091153718, 0.005872693907862854, -0.008123872357421475, -0.058780187362098696, -0.00027467445847377796, 0.024044984289353373, 0.057634827237228584, -0.04450547877367153, -0.03946884506688686, -0.02006971111822632, 0.006139106799438476, 0.014848452844277668, -0.040448605585189826, -0.047422823475079534, 0.00047739853115692137, -0.03920787799786568, -0.05102518756346798, 0.029106281725284004, 0.023013759328845976, -0.0181101632871727, 0.003943383191735267, -0.11744085779379082, 0.00652325401639185, -0.0016088291387550352, 0.004582751362570763, 0.06564233218507957, 0.014525142593546867, -0.05397913284980278, -0.005146496768864823, 0.008265835225847246, -0.09204165418391608, -0.023673615795413973, 0.016221329961976054, 0.0560354235721693, -0.03387280199538708, 0.011243025140723228, 0.02789629877560217, 0.07942785398379296, 0.019745293456116107, -0.03951280953572121, -0.0325216371505229, -0.04877831216997623, 0.008021598871560669, 0.06607214515587043, 0.08340918698473548, -0.06638043362871171, 0.0003533690162649157, -0.05787711264029312, 0.017585791805968413, -0.004768172475530777, -0.031721018591366806, 0.059853391075907716, 0.08903246940908241, 0.00910143805785122, -0.02198764055408287, 0.023417301139897727},
				face.Embedding{0.20730543085474682, -0.006640289179353713, 0.03013410115400314, 0.01258170011165962, -0.023333988977870946, 0.05536234022813034, -0.00010941258007316575, 0.0266348918046072, -0.05017391628723953, 0.026034562221256254, -0.03388911566430759, -0.03461048494812202, 0.040559725024994844, 0.02683793627304573, -0.00972269717541027, -0.07836494561032105, -0.022470260049817198, 0.011276674801708603, -0.05526434009558201, 0.014401617237932205, -0.031258523568474236, -0.05416104192368187, -0.05567222379755878, 0.017950877029356768, -0.016397424193561935, 0.062346790423413276, -0.019043469394284057, 0.04085343435437774, -0.05627231374819698, 0.002355368169155769, 0.07268979656775187, -0.0015096598716884627, -0.030188596848975374, -0.030941932784964564, -0.02826790015985233, -0.05420075791573048, -0.015742074680253033, 0.019360258910790157, -0.008227027287290193, -0.08797317745792674, -0.07358703463505077, 0.09688007249803735, 0.015168583267354964, -0.034569315837825396, 0.054231690688333986, 0.018033145214487362, 0.01579093209709463, -0.09204238994311237, 0.08645247031890774, -0.10499936100221444, 0.022421303168151857, 0.005288450124515152, -0.017391072021601867, 0.011218363053184624, -0.08478270589438915, 0.0038618527485391615, -0.023381522484070015, -0.05428399272960853, -0.049397680150033, 0.04006855272634697, -0.056704127236808774, -0.00958812557516262, -0.024006645464504622, -0.0073450501057456975, -0.03138197361666756, -0.013765138786817361, 0.01162637563227787, 0.0023935177775817563, 0.08953138773108768, 0.05337418268588829, -0.012870218945196915, 0.03652425150877475, -0.027783526080406188, -0.019489638927241745, -0.01591402705199299, -0.005031992847164803, -0.014592982936285286, -0.03540697236418762, 0.015595597412254449, 0.004689344744109726, -0.009276015175478172, 0.0058068592886232374, 0.10480716412028504, 0.0169216338187767, -0.0159497901004467, 0.04574707649004688, -0.012214007484710122, -0.04849749380776977, 0.054958586523843764, 0.055898306713647844, -0.05052226642217827, 0.008803732924324036, 0.02326267119630642, 0.047305830959801676, 0.04497242295638694, 0.020850376996620942, 0.01314765746152954, -0.06768179592533874, 0.05844347174572754, -0.03379152370001783, 0.009412363744416903, 0.04876727547273407, 0.03299943491180715, 0.01981742466488743, 0.0547951049219265, 0.020208802772381018, -0.08163521584288311, -0.038910958658009524, -0.004049565234655952, -0.02227413252290535, -0.0176418922441086, 0.0568860088455925, -0.03240221023084612, 0.0018760896289435579, -0.03234445138420723, 0.007601825631139565, 0.004916589611196899, -0.07292478312312889, 0.021712048014592936, 0.008807552270011749, 0.0045489283733609, 0.018861112444398878, -0.0341377092368577, -0.06305481604926585, 0.039113288345403674, -0.01390809621003151, -0.04930861238819008, 0.02377057523982868, 0.019087416355893325, -0.013899296822125817, 0.02251690464443226, 0.08074113913260841, -0.018922226267959787, 0.07189693789385795, 0.060660045672045707, -0.023638294307546808, -0.006141792394255906, -0.06662582397409247, -0.013895529799502565, 0.016608829923953898, -0.00390724028582611, 0.05038048671591301, -0.015355035841564064, -0.0008532485082750321, -0.004694504582768126, -0.016610601585741958, 0.008180847821889228, -0.04035771976174698, 0.01847608156922703, 0.08409907464663602, -0.029978496458568385, -0.06499117178372192, 0.07448235046571827, 0.10142187900247382, -0.023405319141915855, 0.05237413796294822, 0.04315940939233541, -0.02349721355909328, 0.012594679585403442, -0.10457832859776592, 0.001468614040066719, 0.0165479676672657, -0.07708675453700256, -0.05102918249748802, 0.045642631412478735, -0.004785828004440499, 0.0203317336356945, -0.02006395174473057, 0.04201285855375195, 0.032883700123707296, 0.0477916040669878, 0.08070634492548084, -0.09245629058029556, 0.05112703265588493, -0.006224603994954872, -0.0005257819460310555, 0.005513055457300567, 0.02521921247766018, 0.012207323409280013, -0.009936333046208725, -0.007426916158089448, 0.027260071572856714, 0.006004036209329835, -0.039462719505699156, 0.04428369084658737, 0.005021041270120048, 0.00955255667591259, -0.024385389176467896, 0.06930311634011002, -0.0389855151682066, 0.009325780048200605, 0.0067487294106089776, -0.0538568250434906, -0.04132319716445885, 0.005287871307727813, 0.02836177144018917, 0.016369665767238237, -0.02612976718916588, 0.0781344821977253, 0.0124423230052565, 0.007052016124275589, 0.07093038059380721, -0.040975969278632354, 0.05987170546998787, 0.0429845054696949, 0.06377765311330413, -0.054260408781722336, 0.017124075467253648, 0.011034745989844896, -0.01129856537228031, -0.03058279355517101, -0.052326615682374664, 0.06340472755555274, -0.007235566082305412, 0.08209440086026383, -0.0037407900405261995, -0.02100836190159107, 0.051361881913555715, 0.035520336595121764, 0.019260735587613487, 0.04814414379586697, -0.010566343916274241, -0.03353529212573547, 0.05283452853813282, -0.027749841873006824, -0.03820509264906912, -0.0015166780129867554, 0.02487160170807457, 0.03048850776525669, -0.030538799520168875, 0.0921192664219265, 0.03269134465648327, -0.031787506815418434, -0.01908650508301182, 0.05982613160244779, -0.053232109332236294, -0.03650761934345913, 0.0026813365359365463, 0.032588356136758805, -0.032364926929593085, 0.07780626359498405, 0.044541174425177764, 0.011626562325897788, 0.03554684517681643, -0.030510870967539787, -0.04088990689640999, 0.07105028789278889, 0.03138784011465073, -0.06342823476303319, 0.09164142434876824, -0.0112280279000453, -0.04595559070266152, 0.08798781996626949, 0.026803936697537615, -0.0014241986940294257, -0.020834715982498548, 0.023556784775891685, 0.008996215819517326, -0.0012677171940084454, -0.07692881668502807, 0.024615258007191814, 0.02948731386628723, 0.06911119150276565, -0.041541930091072085, 0.07317672894504547, -0.012252912262506771, -0.03429316172188286, 0.03286905748134327, 0.025736928383919527, 0.003926683415351601, 0.006255630871762562, -0.020806247741813468, 0.0675457214042778, 0.007579460672946357, 0.012004441173839569, -0.028187582314963343, -0.0018772867526912688, -0.01844064376148571, -0.05389302147970715, -0.04154738243111, -0.05912346626385308, -0.003186127453911171, -0.015869915592464562, 0.036601020266580665, -0.08332522355102062, -0.015594113206121387, 0.010554298175920372, 0.009863903175943527, -0.04408378851017952, -0.01321298950931368, -0.026788807387387467, -0.00905998101737915, -0.07901183432849217, 0.022626760559060342, 0.05966787504726859, -0.0373913765745697, -0.00620443077226124, -0.005321248754354935, -0.05629461318153381, -0.04339327553344822, 0.03066110013017902, -0.0560899433873785, 0.029585001932263853, -0.06142458606396866, 0.018855098215825178, 0.03336997769082436, -0.07772387048591708, 0.02869667860757885, 0.04751144987925148, 0.07131169258731747, 0.01554444873138424, -0.019102520424152183, -0.06713599618322277, 0.021553602847260475, 0.022784952935549926, -0.07224605423420524, -0.03428428022313595, 0.025510370273970604, -0.042455744666400605, 0.024999596293880464, 0.0007267671517935561, -0.007103063657435513, 0.051193967364198685, -0.03918299151588478, -0.05340270113635778, -0.0005553757678619388, -0.04361415384515381, -0.05659870360464592, -0.003001301568729019, -0.10493783691904449, 0.007865782491956196, -0.010459198798326888, 0.03839990013440418, -0.029396389004837837, 0.04123072916591454, -0.003870788638888664, 0.011576299454542732, 0.021793958225202522, 0.0013144587776207917, -0.024084851461598205, -0.007895128372669067, 0.02794634672595444, 0.013256276108802492, -0.06581846043538475, -0.03512838380870453, 0.010219935781849479, 0.041956290830379675, -0.02193645334812136, 0.036522118692461206, -0.04014683200312634, -0.007509486720670319, 0.025035869046040268, 0.03341998480559387, -0.03562761249035026, 0.04892323307058029, -0.030771232001644132, -0.016917612628533363, 0.002604945885121918, -0.044643074882380486, 0.01154372547133419, -0.021955625942386627, 0.018907365975515553, 0.03550167291446045, 0.01069377167082758, 0.00010183658435096768, -0.04899959038740444, 0.04724968668608978, -0.01864932432341235, 0.0591259089168789, 0.07907125494612216, 0.028897156624642945, 0.01633692932619137, 0.06420496597867965, 0.018129071607111358, -0.06522170992608013, -0.03939954941189146, 0.04130569647272587, 0.04419998725251961, 0.04542913027885341, 0.018470383181769943, 0.008568164058957863, -0.06659949697784996, -0.053012251715078354, -0.020253768667636778, -0.0428765378002491, 0.07184141544699574, 0.02058260375849676, -0.03779574153167915, 0.0021254573788347247, 0.00922705617390442, -0.06903300705643031, 0.048223514541707424, -0.008124176700399017, 0.06623217639861775, 0.011399885879904556, 0.13320644195552445, -0.015707634324862062, 0.004298537653726769, 0.007440328888434029, -0.03552852988830433, 0.006549433453245544, -0.019685784628289793, 0.001693401851796341, 0.050209905835451124, 0.023254144681681632, -0.04905436637160683, -0.01058279299507389, 0.06261640349854469, -0.07554102380998802, -0.010803172210683784, 0.04001997347501145, -0.013296409033855438, 0.056829244201244355, 0.029110596151947783, 0.006392164909307861, -0.0035876165295053485, -0.019022594469099045, -0.06487911801050472, 0.02178870949222603, 0.05293369045270252, 0.0014374271403566358, 0.02058438161717472, -0.05258523574003887, -0.03312468141761551, 0.051533518133239746, 0.03929023312081566, -0.07294044148252202, 0.01607557897360134, -0.0007034383966050719, 0.014925192443655966, 0.051449392859268764, -0.06079890988933106, -0.04363216685223599, 0.028568039422766974, 0.045766175851156804, 0.07275596444172669, -0.02276483221781349, 0.09294405910429002, 0.06625853254336929, -0.04167032707059745, -0.04751508792911625, -0.014774199240300752, 0.023224616626467326, -0.01281115503053608, 0.03472993899021339, 0.008343472536062031, -0.011408440443860645, 0.004419146704378701, 0.05045044130775452, -0.03518939370823498, -0.04170123182437134, 0.022208642446600917, 0.07141607704347333, -0.04112406919064011, 0.03227901691925602, 0.03527487398910847, -0.029543274091153718, 0.005872693907862854, -0.008123872357421475, -0.058780187362098696, -0.00027467445847377796, 0.024044984289353373, 0.057634827237228584, -0.04450547877367153, -0.03946884506688686, -0.02006971111822632, 0.006139106799438476, 0.014848452844277668, -0.040448605585189826, -0.047422823475079534, 0.00047739853115692137, -0.03920787799786568, -0.05102518756346798, 0.029106281725284004, 0.023013759328845976, -0.0181101632871727, 0.003943383191735267, -0.11744085779379082, 0.00652325401639185, -0.0016088291387550352, 0.004582751362570763, 0.06564233218507957, 0.014525142593546867, -0.05397913284980278, -0.005146496768864823, 0.008265835225847246, -0.09204165418391608, -0.023673615795413973, 0.016221329961976054, 0.0560354235721693, -0.03387280199538708, 0.011243025140723228, 0.02789629877560217, 0.07942785398379296, 0.019745293456116107, -0.03951280953572121, -0.0325216371505229, -0.04877831216997623, 0.008021598871560669, 0.06607214515587043, 0.08340918698473548, -0.06638043362871171, 0.0003533690162649157, -0.05787711264029312, 0.017585791805968413, -0.004768172475530777, -0.031721018591366806, 0.089853391075907716, 0.08903246940908241, 0.00910143805785122, -0.02198764055408287, 0.033417301139897727},
			},
		)

		face2 := entity.NewFace(
			"jqynvsf28rhn6b0c",
			entity.SrcManual,
			face.Embeddings{
				face.Embedding{0.10230543085474682, -0.007840289179353713, 0.03013410115400314, 0.02458170011165962, -0.033333988977870946, 0.06636234022813034, -0.00010941258007316575, 0.0266348918046072, -0.05017391628723953, 0.026034562221256254, -0.03388911566430759, -0.03461048494812202, 0.040559725024994844, 0.02683793627304573, -0.00972269717541027, -0.07836494561032105, -0.022470260049817198, 0.011276674801708603, -0.05526434009558201, 0.014401617237932205, -0.031258523568474236, -0.05416104192368187, -0.05567222379755878, 0.017950877029356768, -0.016397424193561935, 0.062346790423413276, -0.019043469394284057, 0.04085343435437774, -0.05627231374819698, 0.002355368169155769, 0.07268979656775187, -0.0015096598716884627, -0.030188596848975374, -0.030941932784964564, -0.02826790015985233, -0.05420075791573048, -0.015742074680253033, 0.019360258910790157, -0.008227027287290193, -0.08797317745792674, -0.07358703463505077, 0.09688007249803735, 0.015168583267354964, -0.034569315837825396, 0.054231690688333986, 0.018033145214487362, 0.01579093209709463, -0.09204238994311237, 0.08645247031890774, -0.10499936100221444, 0.022421303168151857, 0.005288450124515152, -0.017391072021601867, 0.011218363053184624, -0.08478270589438915, 0.0038618527485391615, -0.023381522484070015, -0.05428399272960853, -0.049397680150033, 0.04006855272634697, -0.056704127236808774, -0.00958812557516262, -0.024006645464504622, -0.0073450501057456975, -0.03138197361666756, -0.013765138786817361, 0.01162637563227787, 0.0023935177775817563, 0.08953138773108768, 0.05337418268588829, -0.012870218945196915, 0.03652425150877475, -0.027783526080406188, -0.019489638927241745, -0.01591402705199299, -0.005031992847164803, -0.014592982936285286, -0.03540697236418762, 0.015595597412254449, 0.004689344744109726, -0.009276015175478172, 0.0058068592886232374, 0.10480716412028504, 0.0169216338187767, -0.0159497901004467, 0.04574707649004688, -0.012214007484710122, -0.04849749380776977, 0.054958586523843764, 0.055898306713647844, -0.05052226642217827, 0.008803732924324036, 0.02326267119630642, 0.047305830959801676, 0.04497242295638694, 0.020850376996620942, 0.01314765746152954, -0.06768179592533874, 0.05844347174572754, -0.03379152370001783, 0.009412363744416903, 0.04876727547273407, 0.03299943491180715, 0.01981742466488743, 0.0547951049219265, 0.020208802772381018, -0.08163521584288311, -0.038910958658009524, -0.004049565234655952, -0.02227413252290535, -0.0176418922441086, 0.0568860088455925, -0.03240221023084612, 0.0018760896289435579, -0.03234445138420723, 0.007601825631139565, 0.004916589611196899, -0.07292478312312889, 0.021712048014592936, 0.008807552270011749, 0.0045489283733609, 0.018861112444398878, -0.0341377092368577, -0.06305481604926585, 0.039113288345403674, -0.01390809621003151, -0.04930861238819008, 0.02377057523982868, 0.019087416355893325, -0.013899296822125817, 0.02251690464443226, 0.08074113913260841, -0.018922226267959787, 0.07189693789385795, 0.060660045672045707, -0.023638294307546808, -0.006141792394255906, -0.06662582397409247, -0.013895529799502565, 0.016608829923953898, -0.00390724028582611, 0.05038048671591301, -0.015355035841564064, -0.0008532485082750321, -0.004694504582768126, -0.016610601585741958, 0.008180847821889228, -0.04035771976174698, 0.01847608156922703, 0.08409907464663602, -0.029978496458568385, -0.06499117178372192, 0.07448235046571827, 0.10142187900247382, -0.023405319141915855, 0.05237413796294822, 0.04315940939233541, -0.02349721355909328, 0.012594679585403442, -0.10457832859776592, 0.001468614040066719, 0.0165479676672657, -0.07708675453700256, -0.05102918249748802, 0.045642631412478735, -0.004785828004440499, 0.0203317336356945, -0.02006395174473057, 0.04201285855375195, 0.032883700123707296, 0.0477916040669878, 0.08070634492548084, -0.09245629058029556, 0.05112703265588493, -0.006224603994954872, -0.0005257819460310555, 0.005513055457300567, 0.02521921247766018, 0.012207323409280013, -0.009936333046208725, -0.007426916158089448, 0.027260071572856714, 0.006004036209329835, -0.039462719505699156, 0.04428369084658737, 0.005021041270120048, 0.00955255667591259, -0.024385389176467896, 0.06930311634011002, -0.0389855151682066, 0.009325780048200605, 0.0067487294106089776, -0.0538568250434906, -0.04132319716445885, 0.005287871307727813, 0.02836177144018917, 0.016369665767238237, -0.02612976718916588, 0.0781344821977253, 0.0124423230052565, 0.007052016124275589, 0.07093038059380721, -0.040975969278632354, 0.05987170546998787, 0.0429845054696949, 0.06377765311330413, -0.054260408781722336, 0.017124075467253648, 0.011034745989844896, -0.01129856537228031, -0.03058279355517101, -0.052326615682374664, 0.06340472755555274, -0.007235566082305412, 0.08209440086026383, -0.0037407900405261995, -0.02100836190159107, 0.051361881913555715, 0.035520336595121764, 0.019260735587613487, 0.04814414379586697, -0.010566343916274241, -0.03353529212573547, 0.05283452853813282, -0.027749841873006824, -0.03820509264906912, -0.0015166780129867554, 0.02487160170807457, 0.03048850776525669, -0.030538799520168875, 0.0921192664219265, 0.03269134465648327, -0.031787506815418434, -0.01908650508301182, 0.05982613160244779, -0.053232109332236294, -0.03650761934345913, 0.0026813365359365463, 0.032588356136758805, -0.032364926929593085, 0.07780626359498405, 0.044541174425177764, 0.011626562325897788, 0.03554684517681643, -0.030510870967539787, -0.04088990689640999, 0.07105028789278889, 0.03138784011465073, -0.06342823476303319, 0.09164142434876824, -0.0112280279000453, -0.04595559070266152, 0.08798781996626949, 0.026803936697537615, -0.0014241986940294257, -0.020834715982498548, 0.023556784775891685, 0.008996215819517326, -0.0012677171940084454, -0.07692881668502807, 0.024615258007191814, 0.02948731386628723, 0.06911119150276565, -0.041541930091072085, 0.07317672894504547, -0.012252912262506771, -0.03429316172188286, 0.03286905748134327, 0.025736928383919527, 0.003926683415351601, 0.006255630871762562, -0.020806247741813468, 0.0675457214042778, 0.007579460672946357, 0.012004441173839569, -0.028187582314963343, -0.0018772867526912688, -0.01844064376148571, -0.05389302147970715, -0.04154738243111, -0.05912346626385308, -0.003186127453911171, -0.015869915592464562, 0.036601020266580665, -0.08332522355102062, -0.015594113206121387, 0.010554298175920372, 0.009863903175943527, -0.04408378851017952, -0.01321298950931368, -0.026788807387387467, -0.00905998101737915, -0.07901183432849217, 0.022626760559060342, 0.05966787504726859, -0.0373913765745697, -0.00620443077226124, -0.005321248754354935, -0.05629461318153381, -0.04339327553344822, 0.03066110013017902, -0.0560899433873785, 0.029585001932263853, -0.06142458606396866, 0.018855098215825178, 0.03336997769082436, -0.07772387048591708, 0.02869667860757885, 0.04751144987925148, 0.07131169258731747, 0.01554444873138424, -0.019102520424152183, -0.06713599618322277, 0.021553602847260475, 0.022784952935549926, -0.07224605423420524, -0.03428428022313595, 0.025510370273970604, -0.042455744666400605, 0.024999596293880464, 0.0007267671517935561, -0.007103063657435513, 0.051193967364198685, -0.03918299151588478, -0.05340270113635778, -0.0005553757678619388, -0.04361415384515381, -0.05659870360464592, -0.003001301568729019, -0.10493783691904449, 0.007865782491956196, -0.010459198798326888, 0.03839990013440418, -0.029396389004837837, 0.04123072916591454, -0.003870788638888664, 0.011576299454542732, 0.021793958225202522, 0.0013144587776207917, -0.024084851461598205, -0.007895128372669067, 0.02794634672595444, 0.013256276108802492, -0.06581846043538475, -0.03512838380870453, 0.010219935781849479, 0.041956290830379675, -0.02193645334812136, 0.036522118692461206, -0.04014683200312634, -0.007509486720670319, 0.025035869046040268, 0.03341998480559387, -0.03562761249035026, 0.04892323307058029, -0.030771232001644132, -0.016917612628533363, 0.002604945885121918, -0.044643074882380486, 0.01154372547133419, -0.021955625942386627, 0.018907365975515553, 0.03550167291446045, 0.01069377167082758, 0.00010183658435096768, -0.04899959038740444, 0.04724968668608978, -0.01864932432341235, 0.0591259089168789, 0.07907125494612216, 0.028897156624642945, 0.01633692932619137, 0.06420496597867965, 0.018129071607111358, -0.06522170992608013, -0.03939954941189146, 0.04130569647272587, 0.04419998725251961, 0.04542913027885341, 0.018470383181769943, 0.008568164058957863, -0.06659949697784996, -0.053012251715078354, -0.020253768667636778, -0.0428765378002491, 0.07184141544699574, 0.02058260375849676, -0.03779574153167915, 0.0021254573788347247, 0.00922705617390442, -0.06903300705643031, 0.048223514541707424, -0.008124176700399017, 0.06623217639861775, 0.011399885879904556, 0.13320644195552445, -0.015707634324862062, 0.004298537653726769, 0.007440328888434029, -0.03552852988830433, 0.006549433453245544, -0.019685784628289793, 0.001693401851796341, 0.050209905835451124, 0.023254144681681632, -0.04905436637160683, -0.01058279299507389, 0.06261640349854469, -0.07554102380998802, -0.010803172210683784, 0.04001997347501145, -0.013296409033855438, 0.056829244201244355, 0.029110596151947783, 0.006392164909307861, -0.0035876165295053485, -0.019022594469099045, -0.06487911801050472, 0.02178870949222603, 0.05293369045270252, 0.0014374271403566358, 0.02058438161717472, -0.05258523574003887, -0.03312468141761551, 0.051533518133239746, 0.03929023312081566, -0.07294044148252202, 0.01607557897360134, -0.0007034383966050719, 0.014925192443655966, 0.051449392859268764, -0.06079890988933106, -0.04363216685223599, 0.028568039422766974, 0.045766175851156804, 0.07275596444172669, -0.02276483221781349, 0.09294405910429002, 0.06625853254336929, -0.04167032707059745, -0.04751508792911625, -0.014774199240300752, 0.023224616626467326, -0.01281115503053608, 0.03472993899021339, 0.008343472536062031, -0.011408440443860645, 0.004419146704378701, 0.05045044130775452, -0.03518939370823498, -0.04170123182437134, 0.022208642446600917, 0.07141607704347333, -0.04112406919064011, 0.03227901691925602, 0.03527487398910847, -0.029543274091153718, 0.005872693907862854, -0.008123872357421475, -0.058780187362098696, -0.00027467445847377796, 0.024044984289353373, 0.057634827237228584, -0.04450547877367153, -0.03946884506688686, -0.02006971111822632, 0.006139106799438476, 0.014848452844277668, -0.040448605585189826, -0.047422823475079534, 0.00047739853115692137, -0.03920787799786568, -0.05102518756346798, 0.029106281725284004, 0.023013759328845976, -0.0181101632871727, 0.003943383191735267, -0.11744085779379082, 0.00652325401639185, -0.0016088291387550352, 0.004582751362570763, 0.06564233218507957, 0.014525142593546867, -0.05397913284980278, -0.005146496768864823, 0.008265835225847246, -0.09204165418391608, -0.023673615795413973, 0.016221329961976054, 0.0560354235721693, -0.03387280199538708, 0.011243025140723228, 0.02789629877560217, 0.07942785398379296, 0.019745293456116107, -0.03951280953572121, -0.0325216371505229, -0.04877831216997623, 0.008021598871560669, 0.06607214515587043, 0.08340918698473548, -0.06638043362871171, 0.0003533690162649157, -0.05787711264029312, 0.017585791805968413, -0.004768172475530777, -0.031721018591366806, 0.059853391075907716, 0.08903246940908241, 0.00910143805785122, -0.02198764055408287, 0.023417301139897727},
			},
		)

		if err := face1.Create(); err != nil {
			t.Fatal(err)
		}

		if err := face2.Create(); err != nil {
			t.Fatal(err)
		}

		faces := entity.Faces{*face1, *face2}

		result, err := MergeFaces(faces, false)

		if err != nil {
			t.Fatal(err)
		}

		assert.Equal(t, "4FD6YTOMWTDU5JKD3SS2MTRUTKZRZT7O", result.ID)
		assert.Equal(t, entity.SrcManual, result.FaceSrc)
		assert.Equal(t, "jqynvsf28rhn6b0c", result.SubjUID)
		assert.Equal(t, 2, result.Samples)
		assert.InDelta(t, 0.040200777224183845, result.SampleRadius, 1e-9)
		assert.Equal(t, 0, result.Collisions)
		assert.Equal(t, float64(0), result.CollisionRadius)

		// t.Logf("merged: %#v", result)
	})
	t.Run("AmbiguousSubjects", func(t *testing.T) {
		face1 := entity.NewFace(
			"jqynvsf28rhn6b0c",
			entity.SrcManual,
			face.Embeddings{
				face.Embedding{0.10730543085474682, -0.007740289179353713, 0.04013410115400314, 0.01458170011165962, -0.033333988977870946, 0.06636234022813034, -0.00010941258007316575, 0.0266348918046072, -0.05017391628723953, 0.026034562221256254, -0.03388911566430759, -0.03461048494812202, 0.040559725024994844, 0.02683793627304573, -0.00972269717541027, -0.07836494561032105, -0.022470260049817198, 0.011276674801708603, -0.05526434009558201, 0.014401617237932205, -0.031258523568474236, -0.05416104192368187, -0.05567222379755878, 0.017950877029356768, -0.016397424193561935, 0.062346790423413276, -0.019043469394284057, 0.04085343435437774, -0.05627231374819698, 0.002355368169155769, 0.07268979656775187, -0.0015096598716884627, -0.030188596848975374, -0.030941932784964564, -0.02826790015985233, -0.05420075791573048, -0.015742074680253033, 0.019360258910790157, -0.008227027287290193, -0.08797317745792674, -0.07358703463505077, 0.09688007249803735, 0.015168583267354964, -0.034569315837825396, 0.054231690688333986, 0.018033145214487362, 0.01579093209709463, -0.09204238994311237, 0.08645247031890774, -0.10499936100221444, 0.022421303168151857, 0.005288450124515152, -0.017391072021601867, 0.011218363053184624, -0.08478270589438915, 0.0038618527485391615, -0.023381522484070015, -0.05428399272960853, -0.049397680150033, 0.04006855272634697, -0.056704127236808774, -0.00958812557516262, -0.024006645464504622, -0.0073450501057456975, -0.03138197361666756, -0.013765138786817361, 0.01162637563227787, 0.0023935177775817563, 0.08953138773108768, 0.05337418268588829, -0.012870218945196915, 0.03652425150877475, -0.027783526080406188, -0.019489638927241745, -0.01591402705199299, -0.005031992847164803, -0.014592982936285286, -0.03540697236418762, 0.015595597412254449, 0.004689344744109726, -0.009276015175478172, 0.0058068592886232374, 0.10480716412028504, 0.0169216338187767, -0.0159497901004467, 0.04574707649004688, -0.012214007484710122, -0.04849749380776977, 0.054958586523843764, 0.055898306713647844, -0.05052226642217827, 0.008803732924324036, 0.02326267119630642, 0.047305830959801676, 0.04497242295638694, 0.020850376996620942, 0.01314765746152954, -0.06768179592533874, 0.05844347174572754, -0.03379152370001783, 0.009412363744416903, 0.04876727547273407, 0.03299943491180715, 0.01981742466488743, 0.0547951049219265, 0.020208802772381018, -0.08163521584288311, -0.038910958658009524, -0.004049565234655952, -0.02227413252290535, -0.0176418922441086, 0.0568860088455925, -0.03240221023084612, 0.0018760896289435579, -0.03234445138420723, 0.007601825631139565, 0.004916589611196899, -0.07292478312312889, 0.021712048014592936, 0.008807552270011749, 0.0045489283733609, 0.018861112444398878, -0.0341377092368577, -0.06305481604926585, 0.039113288345403674, -0.01390809621003151, -0.04930861238819008, 0.02377057523982868, 0.019087416355893325, -0.013899296822125817, 0.02251690464443226, 0.08074113913260841, -0.018922226267959787, 0.07189693789385795, 0.060660045672045707, -0.023638294307546808, -0.006141792394255906, -0.06662582397409247, -0.013895529799502565, 0.016608829923953898, -0.00390724028582611, 0.05038048671591301, -0.015355035841564064, -0.0008532485082750321, -0.004694504582768126, -0.016610601585741958, 0.008180847821889228, -0.04035771976174698, 0.01847608156922703, 0.08409907464663602, -0.029978496458568385, -0.06499117178372192, 0.07448235046571827, 0.10142187900247382, -0.023405319141915855, 0.05237413796294822, 0.04315940939233541, -0.02349721355909328, 0.012594679585403442, -0.10457832859776592, 0.001468614040066719, 0.0165479676672657, -0.07708675453700256, -0.05102918249748802, 0.045642631412478735, -0.004785828004440499, 0.0203317336356945, -0.02006395174473057, 0.04201285855375195, 0.032883700123707296, 0.0477916040669878, 0.08070634492548084, -0.09245629058029556, 0.05112703265588493, -0.006224603994954872, -0.0005257819460310555, 0.005513055457300567, 0.02521921247766018, 0.012207323409280013, -0.009936333046208725, -0.007426916158089448, 0.027260071572856714, 0.006004036209329835, -0.039462719505699156, 0.04428369084658737, 0.005021041270120048, 0.00955255667591259, -0.024385389176467896, 0.06930311634011002, -0.0389855151682066, 0.009325780048200605, 0.0067487294106089776, -0.0538568250434906, -0.04132319716445885, 0.005287871307727813, 0.02836177144018917, 0.016369665767238237, -0.02612976718916588, 0.0781344821977253, 0.0124423230052565, 0.007052016124275589, 0.07093038059380721, -0.040975969278632354, 0.05987170546998787, 0.0429845054696949, 0.06377765311330413, -0.054260408781722336, 0.017124075467253648, 0.011034745989844896, -0.01129856537228031, -0.03058279355517101, -0.052326615682374664, 0.06340472755555274, -0.007235566082305412, 0.08209440086026383, -0.0037407900405261995, -0.02100836190159107, 0.051361881913555715, 0.035520336595121764, 0.019260735587613487, 0.04814414379586697, -0.010566343916274241, -0.03353529212573547, 0.05283452853813282, -0.027749841873006824, -0.03820509264906912, -0.0015166780129867554, 0.02487160170807457, 0.03048850776525669, -0.030538799520168875, 0.0921192664219265, 0.03269134465648327, -0.031787506815418434, -0.01908650508301182, 0.05982613160244779, -0.053232109332236294, -0.03650761934345913, 0.0026813365359365463, 0.032588356136758805, -0.032364926929593085, 0.07780626359498405, 0.044541174425177764, 0.011626562325897788, 0.03554684517681643, -0.030510870967539787, -0.04088990689640999, 0.07105028789278889, 0.03138784011465073, -0.06342823476303319, 0.09164142434876824, -0.0112280279000453, -0.04595559070266152, 0.08798781996626949, 0.026803936697537615, -0.0014241986940294257, -0.020834715982498548, 0.023556784775891685, 0.008996215819517326, -0.0012677171940084454, -0.07692881668502807, 0.024615258007191814, 0.02948731386628723, 0.06911119150276565, -0.041541930091072085, 0.07317672894504547, -0.012252912262506771, -0.03429316172188286, 0.03286905748134327, 0.025736928383919527, 0.003926683415351601, 0.006255630871762562, -0.020806247741813468, 0.0675457214042778, 0.007579460672946357, 0.012004441173839569, -0.028187582314963343, -0.0018772867526912688, -0.01844064376148571, -0.05389302147970715, -0.04154738243111, -0.05912346626385308, -0.003186127453911171, -0.015869915592464562, 0.036601020266580665, -0.08332522355102062, -0.015594113206121387, 0.010554298175920372, 0.009863903175943527, -0.04408378851017952, -0.01321298950931368, -0.026788807387387467, -0.00905998101737915, -0.07901183432849217, 0.022626760559060342, 0.05966787504726859, -0.0373913765745697, -0.00620443077226124, -0.005321248754354935, -0.05629461318153381, -0.04339327553344822, 0.03066110013017902, -0.0560899433873785, 0.029585001932263853, -0.06142458606396866, 0.018855098215825178, 0.03336997769082436, -0.07772387048591708, 0.02869667860757885, 0.04751144987925148, 0.07131169258731747, 0.01554444873138424, -0.019102520424152183, -0.06713599618322277, 0.021553602847260475, 0.022784952935549926, -0.07224605423420524, -0.03428428022313595, 0.025510370273970604, -0.042455744666400605, 0.024999596293880464, 0.0007267671517935561, -0.007103063657435513, 0.051193967364198685, -0.03918299151588478, -0.05340270113635778, -0.0005553757678619388, -0.04361415384515381, -0.05659870360464592, -0.003001301568729019, -0.10493783691904449, 0.007865782491956196, -0.010459198798326888, 0.03839990013440418, -0.029396389004837837, 0.04123072916591454, -0.003870788638888664, 0.011576299454542732, 0.021793958225202522, 0.0013144587776207917, -0.024084851461598205, -0.007895128372669067, 0.02794634672595444, 0.013256276108802492, -0.06581846043538475, -0.03512838380870453, 0.010219935781849479, 0.041956290830379675, -0.02193645334812136, 0.036522118692461206, -0.04014683200312634, -0.007509486720670319, 0.025035869046040268, 0.03341998480559387, -0.03562761249035026, 0.04892323307058029, -0.030771232001644132, -0.016917612628533363, 0.002604945885121918, -0.044643074882380486, 0.01154372547133419, -0.021955625942386627, 0.018907365975515553, 0.03550167291446045, 0.01069377167082758, 0.00010183658435096768, -0.04899959038740444, 0.04724968668608978, -0.01864932432341235, 0.0591259089168789, 0.07907125494612216, 0.028897156624642945, 0.01633692932619137, 0.06420496597867965, 0.018129071607111358, -0.06522170992608013, -0.03939954941189146, 0.04130569647272587, 0.04419998725251961, 0.04542913027885341, 0.018470383181769943, 0.008568164058957863, -0.06659949697784996, -0.053012251715078354, -0.020253768667636778, -0.0428765378002491, 0.07184141544699574, 0.02058260375849676, -0.03779574153167915, 0.0021254573788347247, 0.00922705617390442, -0.06903300705643031, 0.048223514541707424, -0.008124176700399017, 0.06623217639861775, 0.011399885879904556, 0.13320644195552445, -0.015707634324862062, 0.004298537653726769, 0.007440328888434029, -0.03552852988830433, 0.006549433453245544, -0.019685784628289793, 0.001693401851796341, 0.050209905835451124, 0.023254144681681632, -0.04905436637160683, -0.01058279299507389, 0.06261640349854469, -0.07554102380998802, -0.010803172210683784, 0.04001997347501145, -0.013296409033855438, 0.056829244201244355, 0.029110596151947783, 0.006392164909307861, -0.0035876165295053485, -0.019022594469099045, -0.06487911801050472, 0.02178870949222603, 0.05293369045270252, 0.0014374271403566358, 0.02058438161717472, -0.05258523574003887, -0.03312468141761551, 0.051533518133239746, 0.03929023312081566, -0.07294044148252202, 0.01607557897360134, -0.0007034383966050719, 0.014925192443655966, 0.051449392859268764, -0.06079890988933106, -0.04363216685223599, 0.028568039422766974, 0.045766175851156804, 0.07275596444172669, -0.02276483221781349, 0.09294405910429002, 0.06625853254336929, -0.04167032707059745, -0.04751508792911625, -0.014774199240300752, 0.023224616626467326, -0.01281115503053608, 0.03472993899021339, 0.008343472536062031, -0.011408440443860645, 0.004419146704378701, 0.05045044130775452, -0.03518939370823498, -0.04170123182437134, 0.022208642446600917, 0.07141607704347333, -0.04112406919064011, 0.03227901691925602, 0.03527487398910847, -0.029543274091153718, 0.005872693907862854, -0.008123872357421475, -0.058780187362098696, -0.00027467445847377796, 0.024044984289353373, 0.057634827237228584, -0.04450547877367153, -0.03946884506688686, -0.02006971111822632, 0.006139106799438476, 0.014848452844277668, -0.040448605585189826, -0.047422823475079534, 0.00047739853115692137, -0.03920787799786568, -0.05102518756346798, 0.029106281725284004, 0.023013759328845976, -0.0181101632871727, 0.003943383191735267, -0.11744085779379082, 0.00652325401639185, -0.0016088291387550352, 0.004582751362570763, 0.06564233218507957, 0.014525142593546867, -0.05397913284980278, -0.005146496768864823, 0.008265835225847246, -0.09204165418391608, -0.023673615795413973, 0.016221329961976054, 0.0560354235721693, -0.03387280199538708, 0.011243025140723228, 0.02789629877560217, 0.07942785398379296, 0.019745293456116107, -0.03951280953572121, -0.0325216371505229, -0.04877831216997623, 0.008021598871560669, 0.06607214515587043, 0.08340918698473548, -0.06638043362871171, 0.0003533690162649157, -0.05787711264029312, 0.017585791805968413, -0.004768172475530777, -0.031721018591366806, 0.059853391075907716, 0.08903246940908241, 0.00910143805785122, -0.02198764055408287, 0.023417301139897727},
				face.Embedding{0.20730543085474682, -0.006640289179353713, 0.03013410115400314, 0.01258170011165962, -0.023333988977870946, 0.05536234022813034, -0.00010941258007316575, 0.0266348918046072, -0.05017391628723953, 0.026034562221256254, -0.03388911566430759, -0.03461048494812202, 0.040559725024994844, 0.02683793627304573, -0.00972269717541027, -0.07836494561032105, -0.022470260049817198, 0.011276674801708603, -0.05526434009558201, 0.014401617237932205, -0.031258523568474236, -0.05416104192368187, -0.05567222379755878, 0.017950877029356768, -0.016397424193561935, 0.062346790423413276, -0.019043469394284057, 0.04085343435437774, -0.05627231374819698, 0.002355368169155769, 0.07268979656775187, -0.0015096598716884627, -0.030188596848975374, -0.030941932784964564, -0.02826790015985233, -0.05420075791573048, -0.015742074680253033, 0.019360258910790157, -0.008227027287290193, -0.08797317745792674, -0.07358703463505077, 0.09688007249803735, 0.015168583267354964, -0.034569315837825396, 0.054231690688333986, 0.018033145214487362, 0.01579093209709463, -0.09204238994311237, 0.08645247031890774, -0.10499936100221444, 0.022421303168151857, 0.005288450124515152, -0.017391072021601867, 0.011218363053184624, -0.08478270589438915, 0.0038618527485391615, -0.023381522484070015, -0.05428399272960853, -0.049397680150033, 0.04006855272634697, -0.056704127236808774, -0.00958812557516262, -0.024006645464504622, -0.0073450501057456975, -0.03138197361666756, -0.013765138786817361, 0.01162637563227787, 0.0023935177775817563, 0.08953138773108768, 0.05337418268588829, -0.012870218945196915, 0.03652425150877475, -0.027783526080406188, -0.019489638927241745, -0.01591402705199299, -0.005031992847164803, -0.014592982936285286, -0.03540697236418762, 0.015595597412254449, 0.004689344744109726, -0.009276015175478172, 0.0058068592886232374, 0.10480716412028504, 0.0169216338187767, -0.0159497901004467, 0.04574707649004688, -0.012214007484710122, -0.04849749380776977, 0.054958586523843764, 0.055898306713647844, -0.05052226642217827, 0.008803732924324036, 0.02326267119630642, 0.047305830959801676, 0.04497242295638694, 0.020850376996620942, 0.01314765746152954, -0.06768179592533874, 0.05844347174572754, -0.03379152370001783, 0.009412363744416903, 0.04876727547273407, 0.03299943491180715, 0.01981742466488743, 0.0547951049219265, 0.020208802772381018, -0.08163521584288311, -0.038910958658009524, -0.004049565234655952, -0.02227413252290535, -0.0176418922441086, 0.0568860088455925, -0.03240221023084612, 0.0018760896289435579, -0.03234445138420723, 0.007601825631139565, 0.004916589611196899, -0.07292478312312889, 0.021712048014592936, 0.008807552270011749, 0.0045489283733609, 0.018861112444398878, -0.0341377092368577, -0.06305481604926585, 0.039113288345403674, -0.01390809621003151, -0.04930861238819008, 0.02377057523982868, 0.019087416355893325, -0.013899296822125817, 0.02251690464443226, 0.08074113913260841, -0.018922226267959787, 0.07189693789385795, 0.060660045672045707, -0.023638294307546808, -0.006141792394255906, -0.06662582397409247, -0.013895529799502565, 0.016608829923953898, -0.00390724028582611, 0.05038048671591301, -0.015355035841564064, -0.0008532485082750321, -0.004694504582768126, -0.016610601585741958, 0.008180847821889228, -0.04035771976174698, 0.01847608156922703, 0.08409907464663602, -0.029978496458568385, -0.06499117178372192, 0.07448235046571827, 0.10142187900247382, -0.023405319141915855, 0.05237413796294822, 0.04315940939233541, -0.02349721355909328, 0.012594679585403442, -0.10457832859776592, 0.001468614040066719, 0.0165479676672657, -0.07708675453700256, -0.05102918249748802, 0.045642631412478735, -0.004785828004440499, 0.0203317336356945, -0.02006395174473057, 0.04201285855375195, 0.032883700123707296, 0.0477916040669878, 0.08070634492548084, -0.09245629058029556, 0.05112703265588493, -0.006224603994954872, -0.0005257819460310555, 0.005513055457300567, 0.02521921247766018, 0.012207323409280013, -0.009936333046208725, -0.007426916158089448, 0.027260071572856714, 0.006004036209329835, -0.039462719505699156, 0.04428369084658737, 0.005021041270120048, 0.00955255667591259, -0.024385389176467896, 0.06930311634011002, -0.0389855151682066, 0.009325780048200605, 0.0067487294106089776, -0.0538568250434906, -0.04132319716445885, 0.005287871307727813, 0.02836177144018917, 0.016369665767238237, -0.02612976718916588, 0.0781344821977253, 0.0124423230052565, 0.007052016124275589, 0.07093038059380721, -0.040975969278632354, 0.05987170546998787, 0.0429845054696949, 0.06377765311330413, -0.054260408781722336, 0.017124075467253648, 0.011034745989844896, -0.01129856537228031, -0.03058279355517101, -0.052326615682374664, 0.06340472755555274, -0.007235566082305412, 0.08209440086026383, -0.0037407900405261995, -0.02100836190159107, 0.051361881913555715, 0.035520336595121764, 0.019260735587613487, 0.04814414379586697, -0.010566343916274241, -0.03353529212573547, 0.05283452853813282, -0.027749841873006824, -0.03820509264906912, -0.0015166780129867554, 0.02487160170807457, 0.03048850776525669, -0.030538799520168875, 0.0921192664219265, 0.03269134465648327, -0.031787506815418434, -0.01908650508301182, 0.05982613160244779, -0.053232109332236294, -0.03650761934345913, 0.0026813365359365463, 0.032588356136758805, -0.032364926929593085, 0.07780626359498405, 0.044541174425177764, 0.011626562325897788, 0.03554684517681643, -0.030510870967539787, -0.04088990689640999, 0.07105028789278889, 0.03138784011465073, -0.06342823476303319, 0.09164142434876824, -0.0112280279000453, -0.04595559070266152, 0.08798781996626949, 0.026803936697537615, -0.0014241986940294257, -0.020834715982498548, 0.023556784775891685, 0.008996215819517326, -0.0012677171940084454, -0.07692881668502807, 0.024615258007191814, 0.02948731386628723, 0.06911119150276565, -0.041541930091072085, 0.07317672894504547, -0.012252912262506771, -0.03429316172188286, 0.03286905748134327, 0.025736928383919527, 0.003926683415351601, 0.006255630871762562, -0.020806247741813468, 0.0675457214042778, 0.007579460672946357, 0.012004441173839569, -0.028187582314963343, -0.0018772867526912688, -0.01844064376148571, -0.05389302147970715, -0.04154738243111, -0.05912346626385308, -0.003186127453911171, -0.015869915592464562, 0.036601020266580665, -0.08332522355102062, -0.015594113206121387, 0.010554298175920372, 0.009863903175943527, -0.04408378851017952, -0.01321298950931368, -0.026788807387387467, -0.00905998101737915, -0.07901183432849217, 0.022626760559060342, 0.05966787504726859, -0.0373913765745697, -0.00620443077226124, -0.005321248754354935, -0.05629461318153381, -0.04339327553344822, 0.03066110013017902, -0.0560899433873785, 0.029585001932263853, -0.06142458606396866, 0.018855098215825178, 0.03336997769082436, -0.07772387048591708, 0.02869667860757885, 0.04751144987925148, 0.07131169258731747, 0.01554444873138424, -0.019102520424152183, -0.06713599618322277, 0.021553602847260475, 0.022784952935549926, -0.07224605423420524, -0.03428428022313595, 0.025510370273970604, -0.042455744666400605, 0.024999596293880464, 0.0007267671517935561, -0.007103063657435513, 0.051193967364198685, -0.03918299151588478, -0.05340270113635778, -0.0005553757678619388, -0.04361415384515381, -0.05659870360464592, -0.003001301568729019, -0.10493783691904449, 0.007865782491956196, -0.010459198798326888, 0.03839990013440418, -0.029396389004837837, 0.04123072916591454, -0.003870788638888664, 0.011576299454542732, 0.021793958225202522, 0.0013144587776207917, -0.024084851461598205, -0.007895128372669067, 0.02794634672595444, 0.013256276108802492, -0.06581846043538475, -0.03512838380870453, 0.010219935781849479, 0.041956290830379675, -0.02193645334812136, 0.036522118692461206, -0.04014683200312634, -0.007509486720670319, 0.025035869046040268, 0.03341998480559387, -0.03562761249035026, 0.04892323307058029, -0.030771232001644132, -0.016917612628533363, 0.002604945885121918, -0.044643074882380486, 0.01154372547133419, -0.021955625942386627, 0.018907365975515553, 0.03550167291446045, 0.01069377167082758, 0.00010183658435096768, -0.04899959038740444, 0.04724968668608978, -0.01864932432341235, 0.0591259089168789, 0.07907125494612216, 0.028897156624642945, 0.01633692932619137, 0.06420496597867965, 0.018129071607111358, -0.06522170992608013, -0.03939954941189146, 0.04130569647272587, 0.04419998725251961, 0.04542913027885341, 0.018470383181769943, 0.008568164058957863, -0.06659949697784996, -0.053012251715078354, -0.020253768667636778, -0.0428765378002491, 0.07184141544699574, 0.02058260375849676, -0.03779574153167915, 0.0021254573788347247, 0.00922705617390442, -0.06903300705643031, 0.048223514541707424, -0.008124176700399017, 0.06623217639861775, 0.011399885879904556, 0.13320644195552445, -0.015707634324862062, 0.004298537653726769, 0.007440328888434029, -0.03552852988830433, 0.006549433453245544, -0.019685784628289793, 0.001693401851796341, 0.050209905835451124, 0.023254144681681632, -0.04905436637160683, -0.01058279299507389, 0.06261640349854469, -0.07554102380998802, -0.010803172210683784, 0.04001997347501145, -0.013296409033855438, 0.056829244201244355, 0.029110596151947783, 0.006392164909307861, -0.0035876165295053485, -0.019022594469099045, -0.06487911801050472, 0.02178870949222603, 0.05293369045270252, 0.0014374271403566358, 0.02058438161717472, -0.05258523574003887, -0.03312468141761551, 0.051533518133239746, 0.03929023312081566, -0.07294044148252202, 0.01607557897360134, -0.0007034383966050719, 0.014925192443655966, 0.051449392859268764, -0.06079890988933106, -0.04363216685223599, 0.028568039422766974, 0.045766175851156804, 0.07275596444172669, -0.02276483221781349, 0.09294405910429002, 0.06625853254336929, -0.04167032707059745, -0.04751508792911625, -0.014774199240300752, 0.023224616626467326, -0.01281115503053608, 0.03472993899021339, 0.008343472536062031, -0.011408440443860645, 0.004419146704378701, 0.05045044130775452, -0.03518939370823498, -0.04170123182437134, 0.022208642446600917, 0.07141607704347333, -0.04112406919064011, 0.03227901691925602, 0.03527487398910847, -0.029543274091153718, 0.005872693907862854, -0.008123872357421475, -0.058780187362098696, -0.00027467445847377796, 0.024044984289353373, 0.057634827237228584, -0.04450547877367153, -0.03946884506688686, -0.02006971111822632, 0.006139106799438476, 0.014848452844277668, -0.040448605585189826, -0.047422823475079534, 0.00047739853115692137, -0.03920787799786568, -0.05102518756346798, 0.029106281725284004, 0.023013759328845976, -0.0181101632871727, 0.003943383191735267, -0.11744085779379082, 0.00652325401639185, -0.0016088291387550352, 0.004582751362570763, 0.06564233218507957, 0.014525142593546867, -0.05397913284980278, -0.005146496768864823, 0.008265835225847246, -0.09204165418391608, -0.023673615795413973, 0.016221329961976054, 0.0560354235721693, -0.03387280199538708, 0.011243025140723228, 0.02789629877560217, 0.07942785398379296, 0.019745293456116107, -0.03951280953572121, -0.0325216371505229, -0.04877831216997623, 0.008021598871560669, 0.06607214515587043, 0.08340918698473548, -0.06638043362871171, 0.0003533690162649157, -0.05787711264029312, 0.017585791805968413, -0.004768172475530777, -0.031721018591366806, 0.089853391075907716, 0.08903246940908241, 0.00910143805785122, -0.02198764055408287, 0.033417301139897727},
			},
		)

		face2 := entity.NewFace(
			"jqynvt925h8c1asv",
			entity.SrcManual,
			face.Embeddings{
				face.Embedding{0.10230543085474682, -0.007840289179353713, 0.03013410115400314, 0.02458170011165962, -0.033333988977870946, 0.06636234022813034, -0.00010941258007316575, 0.0266348918046072, -0.05017391628723953, 0.026034562221256254, -0.03388911566430759, -0.03461048494812202, 0.040559725024994844, 0.02683793627304573, -0.00972269717541027, -0.07836494561032105, -0.022470260049817198, 0.011276674801708603, -0.05526434009558201, 0.014401617237932205, -0.031258523568474236, -0.05416104192368187, -0.05567222379755878, 0.017950877029356768, -0.016397424193561935, 0.062346790423413276, -0.019043469394284057, 0.04085343435437774, -0.05627231374819698, 0.002355368169155769, 0.07268979656775187, -0.0015096598716884627, -0.030188596848975374, -0.030941932784964564, -0.02826790015985233, -0.05420075791573048, -0.015742074680253033, 0.019360258910790157, -0.008227027287290193, -0.08797317745792674, -0.07358703463505077, 0.09688007249803735, 0.015168583267354964, -0.034569315837825396, 0.054231690688333986, 0.018033145214487362, 0.01579093209709463, -0.09204238994311237, 0.08645247031890774, -0.10499936100221444, 0.022421303168151857, 0.005288450124515152, -0.017391072021601867, 0.011218363053184624, -0.08478270589438915, 0.0038618527485391615, -0.023381522484070015, -0.05428399272960853, -0.049397680150033, 0.04006855272634697, -0.056704127236808774, -0.00958812557516262, -0.024006645464504622, -0.0073450501057456975, -0.03138197361666756, -0.013765138786817361, 0.01162637563227787, 0.0023935177775817563, 0.08953138773108768, 0.05337418268588829, -0.012870218945196915, 0.03652425150877475, -0.027783526080406188, -0.019489638927241745, -0.01591402705199299, -0.005031992847164803, -0.014592982936285286, -0.03540697236418762, 0.015595597412254449, 0.004689344744109726, -0.009276015175478172, 0.0058068592886232374, 0.10480716412028504, 0.0169216338187767, -0.0159497901004467, 0.04574707649004688, -0.012214007484710122, -0.04849749380776977, 0.054958586523843764, 0.055898306713647844, -0.05052226642217827, 0.008803732924324036, 0.02326267119630642, 0.047305830959801676, 0.04497242295638694, 0.020850376996620942, 0.01314765746152954, -0.06768179592533874, 0.05844347174572754, -0.03379152370001783, 0.009412363744416903, 0.04876727547273407, 0.03299943491180715, 0.01981742466488743, 0.0547951049219265, 0.020208802772381018, -0.08163521584288311, -0.038910958658009524, -0.004049565234655952, -0.02227413252290535, -0.0176418922441086, 0.0568860088455925, -0.03240221023084612, 0.0018760896289435579, -0.03234445138420723, 0.007601825631139565, 0.004916589611196899, -0.07292478312312889, 0.021712048014592936, 0.008807552270011749, 0.0045489283733609, 0.018861112444398878, -0.0341377092368577, -0.06305481604926585, 0.039113288345403674, -0.01390809621003151, -0.04930861238819008, 0.02377057523982868, 0.019087416355893325, -0.013899296822125817, 0.02251690464443226, 0.08074113913260841, -0.018922226267959787, 0.07189693789385795, 0.060660045672045707, -0.023638294307546808, -0.006141792394255906, -0.06662582397409247, -0.013895529799502565, 0.016608829923953898, -0.00390724028582611, 0.05038048671591301, -0.015355035841564064, -0.0008532485082750321, -0.004694504582768126, -0.016610601585741958, 0.008180847821889228, -0.04035771976174698, 0.01847608156922703, 0.08409907464663602, -0.029978496458568385, -0.06499117178372192, 0.07448235046571827, 0.10142187900247382, -0.023405319141915855, 0.05237413796294822, 0.04315940939233541, -0.02349721355909328, 0.012594679585403442, -0.10457832859776592, 0.001468614040066719, 0.0165479676672657, -0.07708675453700256, -0.05102918249748802, 0.045642631412478735, -0.004785828004440499, 0.0203317336356945, -0.02006395174473057, 0.04201285855375195, 0.032883700123707296, 0.0477916040669878, 0.08070634492548084, -0.09245629058029556, 0.05112703265588493, -0.006224603994954872, -0.0005257819460310555, 0.005513055457300567, 0.02521921247766018, 0.012207323409280013, -0.009936333046208725, -0.007426916158089448, 0.027260071572856714, 0.006004036209329835, -0.039462719505699156, 0.04428369084658737, 0.005021041270120048, 0.00955255667591259, -0.024385389176467896, 0.06930311634011002, -0.0389855151682066, 0.009325780048200605, 0.0067487294106089776, -0.0538568250434906, -0.04132319716445885, 0.005287871307727813, 0.02836177144018917, 0.016369665767238237, -0.02612976718916588, 0.0781344821977253, 0.0124423230052565, 0.007052016124275589, 0.07093038059380721, -0.040975969278632354, 0.05987170546998787, 0.0429845054696949, 0.06377765311330413, -0.054260408781722336, 0.017124075467253648, 0.011034745989844896, -0.01129856537228031, -0.03058279355517101, -0.052326615682374664, 0.06340472755555274, -0.007235566082305412, 0.08209440086026383, -0.0037407900405261995, -0.02100836190159107, 0.051361881913555715, 0.035520336595121764, 0.019260735587613487, 0.04814414379586697, -0.010566343916274241, -0.03353529212573547, 0.05283452853813282, -0.027749841873006824, -0.03820509264906912, -0.0015166780129867554, 0.02487160170807457, 0.03048850776525669, -0.030538799520168875, 0.0921192664219265, 0.03269134465648327, -0.031787506815418434, -0.01908650508301182, 0.05982613160244779, -0.053232109332236294, -0.03650761934345913, 0.0026813365359365463, 0.032588356136758805, -0.032364926929593085, 0.07780626359498405, 0.044541174425177764, 0.011626562325897788, 0.03554684517681643, -0.030510870967539787, -0.04088990689640999, 0.07105028789278889, 0.03138784011465073, -0.06342823476303319, 0.09164142434876824, -0.0112280279000453, -0.04595559070266152, 0.08798781996626949, 0.026803936697537615, -0.0014241986940294257, -0.020834715982498548, 0.023556784775891685, 0.008996215819517326, -0.0012677171940084454, -0.07692881668502807, 0.024615258007191814, 0.02948731386628723, 0.06911119150276565, -0.041541930091072085, 0.07317672894504547, -0.012252912262506771, -0.03429316172188286, 0.03286905748134327, 0.025736928383919527, 0.003926683415351601, 0.006255630871762562, -0.020806247741813468, 0.0675457214042778, 0.007579460672946357, 0.012004441173839569, -0.028187582314963343, -0.0018772867526912688, -0.01844064376148571, -0.05389302147970715, -0.04154738243111, -0.05912346626385308, -0.003186127453911171, -0.015869915592464562, 0.036601020266580665, -0.08332522355102062, -0.015594113206121387, 0.010554298175920372, 0.009863903175943527, -0.04408378851017952, -0.01321298950931368, -0.026788807387387467, -0.00905998101737915, -0.07901183432849217, 0.022626760559060342, 0.05966787504726859, -0.0373913765745697, -0.00620443077226124, -0.005321248754354935, -0.05629461318153381, -0.04339327553344822, 0.03066110013017902, -0.0560899433873785, 0.029585001932263853, -0.06142458606396866, 0.018855098215825178, 0.03336997769082436, -0.07772387048591708, 0.02869667860757885, 0.04751144987925148, 0.07131169258731747, 0.01554444873138424, -0.019102520424152183, -0.06713599618322277, 0.021553602847260475, 0.022784952935549926, -0.07224605423420524, -0.03428428022313595, 0.025510370273970604, -0.042455744666400605, 0.024999596293880464, 0.0007267671517935561, -0.007103063657435513, 0.051193967364198685, -0.03918299151588478, -0.05340270113635778, -0.0005553757678619388, -0.04361415384515381, -0.05659870360464592, -0.003001301568729019, -0.10493783691904449, 0.007865782491956196, -0.010459198798326888, 0.03839990013440418, -0.029396389004837837, 0.04123072916591454, -0.003870788638888664, 0.011576299454542732, 0.021793958225202522, 0.0013144587776207917, -0.024084851461598205, -0.007895128372669067, 0.02794634672595444, 0.013256276108802492, -0.06581846043538475, -0.03512838380870453, 0.010219935781849479, 0.041956290830379675, -0.02193645334812136, 0.036522118692461206, -0.04014683200312634, -0.007509486720670319, 0.025035869046040268, 0.03341998480559387, -0.03562761249035026, 0.04892323307058029, -0.030771232001644132, -0.016917612628533363, 0.002604945885121918, -0.044643074882380486, 0.01154372547133419, -0.021955625942386627, 0.018907365975515553, 0.03550167291446045, 0.01069377167082758, 0.00010183658435096768, -0.04899959038740444, 0.04724968668608978, -0.01864932432341235, 0.0591259089168789, 0.07907125494612216, 0.028897156624642945, 0.01633692932619137, 0.06420496597867965, 0.018129071607111358, -0.06522170992608013, -0.03939954941189146, 0.04130569647272587, 0.04419998725251961, 0.04542913027885341, 0.018470383181769943, 0.008568164058957863, -0.06659949697784996, -0.053012251715078354, -0.020253768667636778, -0.0428765378002491, 0.07184141544699574, 0.02058260375849676, -0.03779574153167915, 0.0021254573788347247, 0.00922705617390442, -0.06903300705643031, 0.048223514541707424, -0.008124176700399017, 0.06623217639861775, 0.011399885879904556, 0.13320644195552445, -0.015707634324862062, 0.004298537653726769, 0.007440328888434029, -0.03552852988830433, 0.006549433453245544, -0.019685784628289793, 0.001693401851796341, 0.050209905835451124, 0.023254144681681632, -0.04905436637160683, -0.01058279299507389, 0.06261640349854469, -0.07554102380998802, -0.010803172210683784, 0.04001997347501145, -0.013296409033855438, 0.056829244201244355, 0.029110596151947783, 0.006392164909307861, -0.0035876165295053485, -0.019022594469099045, -0.06487911801050472, 0.02178870949222603, 0.05293369045270252, 0.0014374271403566358, 0.02058438161717472, -0.05258523574003887, -0.03312468141761551, 0.051533518133239746, 0.03929023312081566, -0.07294044148252202, 0.01607557897360134, -0.0007034383966050719, 0.014925192443655966, 0.051449392859268764, -0.06079890988933106, -0.04363216685223599, 0.028568039422766974, 0.045766175851156804, 0.07275596444172669, -0.02276483221781349, 0.09294405910429002, 0.06625853254336929, -0.04167032707059745, -0.04751508792911625, -0.014774199240300752, 0.023224616626467326, -0.01281115503053608, 0.03472993899021339, 0.008343472536062031, -0.011408440443860645, 0.004419146704378701, 0.05045044130775452, -0.03518939370823498, -0.04170123182437134, 0.022208642446600917, 0.07141607704347333, -0.04112406919064011, 0.03227901691925602, 0.03527487398910847, -0.029543274091153718, 0.005872693907862854, -0.008123872357421475, -0.058780187362098696, -0.00027467445847377796, 0.024044984289353373, 0.057634827237228584, -0.04450547877367153, -0.03946884506688686, -0.02006971111822632, 0.006139106799438476, 0.014848452844277668, -0.040448605585189826, -0.047422823475079534, 0.00047739853115692137, -0.03920787799786568, -0.05102518756346798, 0.029106281725284004, 0.023013759328845976, -0.0181101632871727, 0.003943383191735267, -0.11744085779379082, 0.00652325401639185, -0.0016088291387550352, 0.004582751362570763, 0.06564233218507957, 0.014525142593546867, -0.05397913284980278, -0.005146496768864823, 0.008265835225847246, -0.09204165418391608, -0.023673615795413973, 0.016221329961976054, 0.0560354235721693, -0.03387280199538708, 0.011243025140723228, 0.02789629877560217, 0.07942785398379296, 0.019745293456116107, -0.03951280953572121, -0.0325216371505229, -0.04877831216997623, 0.008021598871560669, 0.06607214515587043, 0.08340918698473548, -0.06638043362871171, 0.0003533690162649157, -0.05787711264029312, 0.017585791805968413, -0.004768172475530777, -0.031721018591366806, 0.059853391075907716, 0.08903246940908241, 0.00910143805785122, -0.02198764055408287, 0.023417301139897727},
			},
		)

		faces := entity.Faces{*face1, *face2}

		result, err := MergeFaces(faces, false)

		assert.EqualError(t, err, "faces: cannot merge clusters with conflicting subjects jqynvsf28rhn6b0c <> jqynvt925h8c1asv")
		assert.Nil(t, result)
	})
	t.Run("OneSubject", func(t *testing.T) {
		result, err := MergeFaces(entity.Faces{entity.Face{ID: "4FD6YTOMWTDU5JKD3SS2MTRUTKZRZT7O"}}, false)

		assert.EqualError(t, err, "faces: two or more clusters required for merging")
		assert.Nil(t, result)
	})
}

func TestMergeFacesRetainedClusters(t *testing.T) {
	subjUID := rnd.GenerateUID('j')

	embeddingA := face.RandomEmbeddings(1, face.RegularFace)
	embeddingB := face.RandomEmbeddings(1, face.RegularFace)

	faceA := entity.NewFace(subjUID, entity.SrcManual, embeddingA)
	require.NoError(t, faceA.Create())

	faceB := entity.NewFace(subjUID, entity.SrcManual, embeddingB)
	require.NoError(t, faceB.Create())

	// Create markers that deliberately fail to match the merged embedding.
	neutralEmbedding := face.Embeddings{face.NullEmbedding}
	neutralJSON := neutralEmbedding.JSON()

	markers := []*entity.Marker{
		{
			FileUID:        rnd.GenerateUID('f'),
			MarkerType:     entity.MarkerFace,
			MarkerSrc:      entity.SrcManual,
			FaceID:         faceA.ID,
			EmbeddingsJSON: neutralJSON,
		},
		{
			FileUID:        rnd.GenerateUID('f'),
			MarkerType:     entity.MarkerFace,
			MarkerSrc:      entity.SrcManual,
			FaceID:         faceB.ID,
			EmbeddingsJSON: neutralJSON,
		},
	}

	for _, marker := range markers {
		require.NoError(t, entity.Db().Create(marker).Error)
	}

	_, err := MergeFaces(entity.Faces{*faceA, *faceB}, false)
	require.Error(t, err)
	require.True(t, errors.Is(err, ErrRetainedManualClusters))

	var updated entity.Face
	require.NoError(t, entity.Db().Where("id = ?", faceA.ID).First(&updated).Error)
	require.NotZero(t, updated.MergeRetry)
	require.NotEmpty(t, updated.MergeNotes)

	resetCount, err := ResetFaceMergeRetry(subjUID)
	require.NoError(t, err)
	require.GreaterOrEqual(t, resetCount, 1)

	require.NoError(t, entity.Db().Where("id = ?", faceA.ID).First(&updated).Error)
	require.Zero(t, updated.MergeRetry)
	require.Empty(t, updated.MergeNotes)
}

func TestResolveFaceCollisions(t *testing.T) {
	c, r, err := ResolveFaceCollisions()

	if err != nil {
		t.Fatal(err)
	}

	assert.LessOrEqual(t, 1, c)
	assert.LessOrEqual(t, 1, r)
}

func TestRemoveAutoFaceClusters(t *testing.T) {
	removed, err := RemoveAutoFaceClusters()

	if err != nil {
		t.Fatal(err)
	}

	assert.LessOrEqual(t, 3, removed)
}
